﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KopeykaStore.Models;

namespace KopeykaStore.Controllers
{
    public class StoreController : Controller
    {
        readonly KopeykaStoreEntities StoreDb = new KopeykaStoreEntities();
        
        //
        // GET: /Store/
        public ActionResult Index()
        {
            var ModelCategories = StoreDb.Categories.ToList();
            return View(ModelCategories);
            //var ModelCategory = StoreDb.Products.ToList();
            //return View(ModelCategory);
        }

        //
        // GET: /Store/Browse?category=Shorts

        public ActionResult Browse(string category)
        {
            var ModelCategory = StoreDb.Categories.Include("Products").Single(g => g.Name == category);
            
            //return "StoreController.Browse()"; // for debug
            return View(ModelCategory);
        }
        //
        // GET: /Store/Details/2

        public ActionResult Details(int id)
        {
            var Product = StoreDb.Products.Single(p => p.ProductId == id);

            //return "StoreController.Details()"; // for debug
            return View(Product);
        }

        //
        // GET: /Store/Brand/2

        public ActionResult Brand(int id)
        {
            var Brand = StoreDb.Brands.Single(p => p.BrandId == id);
            return View(Brand);
        }

        //
        // GET: /Store/CategoryMenu

        [ChildActionOnly]
        public ActionResult CategoryMenu()
        {
            var Categories = StoreDb.Categories.ToList();
            return PartialView(Categories);
        }

        //
        // GET: /Store/BrandMenu

        [ChildActionOnly]
        public ActionResult BrandMenu()
        {
            var Brands = StoreDb.Brands.ToList();
            return PartialView(Brands);
        }

    }
}
